package com.cos.shop.common;

/**
 * @author: COS
 * @time: 2023/5/10 9:09
 * @description:
 * 统一返回数据类型
 */
public class ResponseResult<T> {
    /**
     * @author: COS
     * @time: 2023/5/10 9:09
     * @description: 这次响应的状态 0失败 1成功 2已登录 3未登录
     */
    private int code;
    /**
     * @author: COS
     * @time: 2023/5/10 9:10
     * @description: 提示信息 成功登录 新增成功 修改成功 ...
     */
    private String msg;
    /**
     * @author: COS
     * @time: 2023/5/10 9:10
     * @description: 成功后获取到的数据 list
     */
    private T t;
    /* 设置通用的成功失败响应 */
    // 设置通用的成功响应
    public static ResponseResult createSuccess(){
        // 使用ResponseCode 设置默认的成功响应代码和成功响应信息
        return new ResponseResult(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg());
    }
    public static ResponseResult createSuccess(String msg){
        // 使用ResponseCode 设置默认的成功响应代码,和自定义的响应信息
        return new ResponseResult(ResponseCode.SUCCESS.getCode(), msg);
    }
    public static ResponseResult createSuccess(int code , String msg){
        // 使用ResponseCode 设置默认的成功自定义响应代码,和自定义的响应信息
        return new ResponseResult(code, msg);
    }
    public static <T> ResponseResult createSuccess(T data){
        // 使用ResponseCode 设置默认的成功响应代码,和响应信息,响应数据
        return new ResponseResult(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg(),data);
    }
    // 设置通用的失败响应
    public static ResponseResult createFail(){
        // 使用ResponseCode 设置默认的成功响应代码和成功响应信息
        return new ResponseResult(ResponseCode.FAIL.getCode(), ResponseCode.FAIL.getMsg());
    }
    public static ResponseResult createFail(String msg){
        // 使用ResponseCode 设置默认的成功响应代码,和自定义的响应信息
        return new ResponseResult(ResponseCode.FAIL.getCode(), msg);
    }
    public static ResponseResult createFail(int code , String msg){
        // 使用ResponseCode 设置默认的成功自定义响应代码,和自定义的响应信息
        return new ResponseResult(code, msg);
    }
    public static <T> ResponseResult createFail(T data){
        // 使用ResponseCode 设置默认的成功响应代码,和响应信息,响应数据
        return new ResponseResult(ResponseCode.FAIL.getCode(), ResponseCode.FAIL.getMsg(),data);
    }
    public static <T> ResponseResult createResult(int code ,String msg ,T data){
        return new ResponseResult(code, msg, data);
    }

    /* 结束 */
    public ResponseResult(int code, T t) {
        this.code = code;
        this.t = t;
    }

    public ResponseResult(T t) {
        this.t = t;
    }

    public ResponseResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(int code, String msg, T t) {
        this.code = code;
        this.msg = msg;
        this.t = t;
    }

    public ResponseResult() {
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getT() {
        return t;
    }

    public void setT(T t) {
        this.t = t;
    }
}
